package com.xqls.dal.dao.mybatis;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.xqls.dal.dao.FlowRecordDao;
import com.xqls.dal.model.FlowRecord;
import com.xqls.dal.model.FlowRecordExample;
import com.xqls.dal.service.FlowRecordMapper;
import com.xqls.util.ObjectUtil;
@Repository
public class FlowRecordDaoImpl implements FlowRecordDao {
	
	@Autowired
	private FlowRecordMapper flowMapper;
	

	@Override
	public int insert(FlowRecord record) {
		return flowMapper.insert(record);
	}
	

	@Override
	public List<Map<String, Object>> selectMinByMap(Map<String, Object> map) {
		return flowMapper.selectMinByMap(map);
	}


	@Override
	public List<Map<String, Object>> selectHourByMap(Map<String, Object> map) {
		return flowMapper.selectHourByMap(map);
	}


	@Override
	public List<Map<String, Object>> selectDayByMap(Map<String, Object> map) {
		return flowMapper.selectDayByMap(map);
	}


	@Override
	public List<Map<String, Object>> selectMonthByMap(Map<String, Object> map) {
		return flowMapper.selectMonthByMap(map);
	}


	@Override
	public List<Map<String, Object>> selectYearByMap(Map<String, Object> map) {
		List<Map<String, Object>> list = flowMapper.selectYearByMap(map);
		return list;
	}


	@Override
	public Map<String, Object> selDayCumulativeFlow(Map<String, Object> map) {
		return flowMapper.selDayCumulativeFlow(map);
	}


	@Override
	public int insertToMonth(Map<String, Object> map) {
		flowMapper.deleteMonth(map);
		int result = flowMapper.insertToMonth(map);
		return result;
	}

	@Override
	public int insertToDay(Map<String, Object> map) {
		flowMapper.deleteDay(map);
		int result = flowMapper.insertToDay(map);
		return result;
	}

	@Override
	public Map<String, Object> selectYearColumn(Map<String, Object> map) {
		return flowMapper.selectYearColumn(map);
	}


	@Override
	public Map<String, Object> selectMapFromFlow(Map<String, Object> map) {
		return flowMapper.selectDayMax(map);
	}


	@Override
	public Map<String, Object> selectMapFromDayFlow(Map<String, Object> map) {
		return flowMapper.selectMonthMax(map);
	}


	@Override
	public Map<String, Object> selectMaxBeforeThisByMap(Map<String, Object> map) {
		return flowMapper.selectMaxBeforeThisByMap(map);
	}


	@Override
	public List<Map<String, Object>> getMinuteListByMap(Map<String, Object> map) {
		return this.flowMapper.getMinuteListByMap(map);
	}


	@Override
	public List<Map<String, Object>> getHourListByMap(Map<String, Object> map) {
		return this.flowMapper.getHourListByMap(map);
	}


	@Override
	public List<Map<String, Object>> getDayListByMap(Map<String, Object> map) {
		return this.flowMapper.getDayListByMap(map);
	}


	@Override
	public List<Map<String, Object>> getMonthListByMap(Map<String, Object> map) {
		return this.flowMapper.getMonthListByMap(map);
	}


	@Override
	public List<Map<String, Object>> getYearListByMap(Map<String, Object> map) {
		return this.flowMapper.getYearListByMap(map);
	}


	@Override
	public FlowRecord selflow(String deviceNo, String closeMonth) {
		Map<String , Object> map =new HashMap<String, Object>();
		map.put("enterpriseNo", deviceNo);
		map.put("recordingTime", closeMonth);
		Map<String, Object> datamap = flowMapper.selflow(map);
		FlowRecord flow = (FlowRecord) ObjectUtil.transfer(datamap, FlowRecord.class);
		if(datamap != null){
			flow.setCumulativeFlow((Double)datamap.get("accumuLate"));
		}
		//flow.setCumulativeFlow((Double)datamap.get("accumuLate"));
		return  flow;
	}

}
